﻿namespace SpikingVisualisationRLib

open SpikingAnalyticsLib
open RProvider
open RProvider.RInterop
open RProvider.``base``
open RProvider.graphics
open RProvider.grDevices

/// Utilities functions for all visualisation types

type SaveFormat =
   | Jpg = 0
   | Png = 1
   | Pdf = 2

[<AbstractClass; Sealed>]
type VisualisationUtilities () =

    /// Open a new plot window (only necessary when plotting in multiple windows)
    static member NewWindow () = R.dev_new() |> ignore

    /// Save the open plot window to the specified file path
    static member SavePlot (savePath:PathDescriptor, saveFormat:SaveFormat) =
        let format =
            match saveFormat with
            | SaveFormat.Jpg -> "jpg"
            | SaveFormat.Png -> "png"
            | SaveFormat.Pdf -> "pdf"
            | _ -> "jpg"

        R.savePlot(savePath.Path(format), format) |> ignore
